home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4973 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: odi.com!usenet
  2. From: Kimberley Burchett <burchett>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Aborting Constructors, Part II
  5. Date: 1 Feb 1996 22:36:02 GMT
  6. Organization: Software Leverage, Inc
  7. Message-ID: <4erf8i$g0b@mastermind.odi.com>
  8. References: <4eoeck$t6n@news.ios.com>
  9. NNTP-Posting-Host: loon.odi.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4c)
  14. X-URL: news:4eoeck$t6n@news.ios.com
  15.  
  16. leonardj@tribeca.ios.com (John Leonard) wrote:
  17. >
  18. >    Earlier, I posted a message about aborting a constructor if for some
  19. >reason some resource cannot be allocated. I did some thinking about
  20. >the problem and I thought, why couldn't you just call 'delete' inside
  21. >of the constructor itself and then let the destructor take care of the
  22. >release of all resources allocated so far.
  23.  
  24.   1) it requires that the object was allocated with new.  If the object is
  25. on the stack or in an STL container, this will not work.
  26.  
  27.   2) if the constructor is being called as part of constructing a derived
  28. class, then once the base class constructor is done, the derived class's
  29. constructor takes over and will most likely not realize that "this" is no 
  30. longer valid.
  31.  
  32.   3) there is no way for the creator of the object to know whether the
  33. object it just created is usable.  It also doesn't know whether it should
  34. delete the object or the object has already deleted itself.  You can't
  35. ask the object whether it's usable because the object may not exist any 
  36. more.
  37.  
  38. The Microsoft Foundation Classes do use "delete this" when destroying
  39. modeless dialogs.  Basically they use it as a kind of garbage collection;
  40. they can create a modeless dialog on the heap without storing the 
  41. pointer, and the window will destroy itself as soon as it closes.  But
  42. this happens *after* the user is done with the window -- *not* before
  43. the window is created.
  44.  
  45. Kimberley
  46.  
  47.